package com.zygh.lz.controller.pc;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zygh.lz.entity.WarningEducation;
import com.zygh.lz.service.impl.WarningEducationService;
import com.zygh.lz.stapprove.ResultUtil;
import com.zygh.lz.stapprove.SysPcLog;
import com.zygh.lz.vo.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Api(tags = "警示教育")
@RestController
@RequestMapping("/WarningEducation")
public class WarningEducationController {

    @Resource
    private WarningEducationService warningEducationService;

    @ApiOperation(value = "新增警示教育")
    @PostMapping("addAppraise")
    //@SysPcLog(module = "新增警示教育",operation = "新增")
    public ResultBean addAppraise(@Validated @RequestBody WarningEducation warningEducation) {
        warningEducation.setCreatTime(new Date());
        warningEducationService.save(warningEducation);
        return ResultUtil.setOK("success", null);
    }

    @ApiOperation(value = "删除警示教育")
    @PostMapping("deleteAppraise/{id}")
    //@SysPcLog(module = "删除警示教育",operation = "删除")
    public ResultBean deleteAppraise(@PathVariable("id") Long id) {
        warningEducationService.removeById(id);
        return ResultUtil.setOK("success", null);
    }

    @ApiOperation(value = "修改警示教育")
    @PostMapping("updateAppraise")
    //@SysPcLog(module = "修改警示教育",operation = "修改")
    public ResultBean updateAppraise(@Validated @RequestBody WarningEducation warningEducation) {
        warningEducationService.updateById(warningEducation);
        return ResultUtil.setOK("success", null);
    }

    @ApiOperation(value = "查询有效警示教育")
    @GetMapping("findAppraiseAll")
    public ResultBean findAppraiseAll(@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                      @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<WarningEducation> list = warningEducationService.list(new QueryWrapper<WarningEducation>()
                .eq("state", 1));
        return ResultUtil.setOK("success", new PageInfo<>(list));
    }

}
